package cn.pan.controller;

import cn.pan.service.EsRestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping
public class IndexController {

    @Autowired
    EsRestService restService;

    @RequestMapping("/")
    public String index() {
        return "index";
    }

    @RequestMapping("/search")
    public String search() {
        return "result";
    }

    @RequestMapping("/find")
    @ResponseBody
    public Map<String, Object> find(
            @RequestParam("keyword") String keyword,
            @RequestParam(value = "pn", defaultValue = "1") Integer pn) {
        String[] searchFields = {"title", "filecontent"};

        Map<String, Object> dataMap = restService.searchDocs("userdoc",
                keyword, searchFields, pn, 10);

        return dataMap;
    }
}
